Getters¶
TTP template variables also support a number of getters - functions targeted to get some information and assign it to variable. Getters called for each input datum.
Function | Description |
---|---|
gethostname | this function tries to extract hostname out of source data prompts |
getfilename | returns a name of the source data |
get_time | returns current time |
get_date | returns current date |
get_timestamp | returns combination of current date and time |
get_timestamp_ms | returns combination of current date and time with milliseconds |
get_timestamp_iso | returns timestamp in ISO format in UTC timezone |
get_time_ns | returns current time in nanoseconds since Epoch |
gethostname¶
var_name="gethostname"
Using this getter function TTP tries to extract device’s hostname out of it prompt.
Supported prompts are:
- Juniper such as
some.user@hostname>
- Huawei such as
<hostname>
- Cisco IOS Exec such as
hostname>
- Cisco IOS XR such as
RP/0/4/CPU0:hostname#
- Cisco IOS Priviledged such as
hostname#
- Fortigate such as
hostname (context) #
Example
Template:
<input load="text">
switch1#show run int
interface GigabitEthernet3/11
description input_1_data
</input>
<vars name="vars">
hostname_var = "gethostname"
</vars>
<group name="interfaces">
interface {{ interface }}
description {{ description }}
</group>
Result:
[
{
"interfaces": {
"description": "input_1_data",
"interface": "GigabitEthernet3/11"
},
"vars": {
"hostname_var": "switch1"
}
}
]
getfilename¶
var_name="getfilename"
This function returns the name of input data file if data was loaded from file, if data was loaded from text it will return “text_data”.
get_timestamp_ms¶
var_name="get_timestamp_ms"
Returns current timestamp but with milliseconds precision in a format of %Y-%m-%d %H:%M:%S.%ms
get_timestamp_iso¶
var_name="get_timestamp_iso"
Returns current timestamp in ISO format with UTC timezone e.g. 2020-06-30T11:07:01.212349+00:00
. Uses python datetime function to produce timestamp.
get_time_ns¶
var_name="get_time_ns"
This function uses time.time_ns method to return current time in nanoseconds since Epoch